<template>
  <view class="my-address-list-page">
    <!-- 顶部导航栏 -->
    <!-- <view class="header-nav">
      <view class="nav-content">
        <view class="back-btn" @click="goBack">
          <text class="iconfont-v2 icon-youjiantou back-icon" style="transform: rotate(180deg);"></text>
        </view>
        <view class="page-title">我的地址</view>
        <view class="header-actions">
          <text class="iconfont-v2 icon-gengduo more-icon"></text>
        </view>
      </view>
    </view> -->

    <!-- 地址列表 -->
    <view class="address-list">
      <view 
        class="address-item" 
        :class="{ 'default-address': address.isDefault }"
        v-for="(address, index) in addressList" 
        :key="index"
        @click="selectAddress(address)"
      >
        <view class="address-content">
          <view class="address-info">
            <text class="address-text">{{ address.fullAddress }}</text>
            <text class="contact-info">{{ address.contactName }} {{ address.phoneNumber }}</text>
          </view>
        </view>
        <text class="iconfont-v2 icon-weibiaoti--copy status-icon" v-if="address.isDefault"></text>
      </view>
    </view>

    <!-- 底部新增地址按钮 -->
    <view class="bottom-action">
      <button class="add-address-btn" @click="addNewAddress">
        <text>新增地址</text>
      </button>
    </view>
  </view>
</template>

<script>
export default {
  data() {
    return {
      // 地址列表数据
      addressList: [
        {
          id: 1,
          fullAddress: "南宁市西乡塘区北湖南路32号",
          contactName: "龙霞",
          phoneNumber: "17864110900",
          isDefault: false
        },
        {
          id: 2,
          fullAddress: "南宁市西乡塘区北湖南路132号",
          contactName: "龙霞",
          phoneNumber: "17864110900",
          isDefault: true
        }
      ]
    }
  },
  methods: {
    goBack() {
      uni.navigateBack();
    },
    selectAddress(address) {
      // 设置选中的地址为默认地址
      this.addressList.forEach(addr => {
        addr.isDefault = false;
      });
      address.isDefault = true;
      
      console.log('选择地址:', address);
      
      // 这里可以添加选择地址后的逻辑，比如返回上一页并传递地址信息
      // 或者保存到全局状态管理
    },
    addNewAddress() {
      console.log('跳转到新增地址页面');
      uni.navigateTo({
        url: '/pages/fast/add-address-new'
      });
    },
    // 编辑地址
    editAddress(address) {
      console.log('编辑地址:', address);
      // 可以跳转到编辑地址页面，传递地址ID
    },
    // 删除地址
    deleteAddress(address) {
      uni.showModal({
        title: '确认删除',
        content: '确定要删除这个地址吗？',
        success: (res) => {
          if (res.confirm) {
            const index = this.addressList.findIndex(addr => addr.id === address.id);
            if (index > -1) {
              this.addressList.splice(index, 1);
              uni.showToast({
                title: '删除成功',
                icon: 'success'
              });
            }
          }
        }
      });
    }
  }
}
</script>

<style lang="scss" scoped>
.my-address-list-page {
  min-height: 100vh;
  background: #f5f5f5;
  display: flex;
  flex-direction: column;
}

.header-nav {
  background: transparent;
  padding: 20rpx 30rpx;
  padding-top: 80rpx;
  
  .nav-content {
    display: flex;
    align-items: center;
    justify-content: space-between;
    
    .back-btn {
      width: 80rpx;
      height: 80rpx;
      display: flex;
      align-items: center;
      justify-content: center;
      cursor: pointer;
      
      .back-icon {
        font-size: 40rpx;
        color: #333;
      }
    }
    
    .page-title {
      font-size: 36rpx;
      font-weight: 600;
      color: #333;
    }
    
    .header-actions {
      width: 80rpx;
      height: 80rpx;
      display: flex;
      align-items: center;
      justify-content: center;
      
      .more-icon {
        font-size: 36rpx;
        color: #666;
        cursor: pointer;
      }
    }
  }
}

.address-list {
  flex: 1;
  padding: 20rpx;
  
  .address-item {
    background: white;
    border-radius: 24rpx;
    padding: 30rpx;
    margin-bottom: 20rpx;
    display: flex;
    align-items: center;
    justify-content: space-between;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4rpx 16rpx rgba(0, 0, 0, 0.08);
    
    &:hover {
      transform: translateY(-2rpx);
      box-shadow: 0 8rpx 24rpx rgba(0, 0, 0, 0.12);
    }
    
    &.default-address {
      border: 2rpx solid #ED6567;
    }
    
    .address-content {
      flex: 1;
      
      .address-info {
        .address-text {
          font-size: 32rpx;
          color: #333;
          font-weight: 500;
          margin-bottom: 8rpx;
          display: block;
        }
        
        .contact-info {
          font-size: 28rpx;
          color: #666;
          display: block;
        }
      }
    }
    
    .status-icon {
      font-size: 32rpx;
      color: #ED6567;
      margin-left: 20rpx;
    }
  }
}

.bottom-action {
  padding: 20rpx;
  background: white;
  border-top: 2rpx solid #f0f0f0;
  
  .add-address-btn {
    width: 100%;
    height: 100rpx;
    background: #ED6567;
    border: none;
    border-radius: 50rpx;
    font-size: 36rpx;
    color: white;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    justify-content: center;
    align-items: center;
    
    &:hover {
      background: #d55a54;
      transform: translateY(-2rpx);
    }
    
    &:active {
      transform: translateY(0);
    }
  }
}
</style>